import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';

import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
// import ElementPlus from 'unplugin-element-plus/vite';

console.log('process.env.NODE_ENV', process.env.NODE_ENV);

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    // ElementPlus({
    //   useSource: true
    // })
  ],
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src')
    }
  },
  // css: {
  //   preprocessorOptions: {
  //     scss: {
  //       additionalData: `@use "@/styles/element/index.scss" as *;`
  //     }
  //   }
  // },

  base: '/',
  build: {
    outDir: 'dist',
    assetsDir: 'admin/assets'
  },

  server: {
    port: 7702,
    proxy: {
      // '^/upload/attachment/.*': {
      //   target: 'https://shop.wjintian.com',
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/upload/, '')
      // }

      '^/api/.*': {
        target: 'http://localhost:3032',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },

      '^/upload/.*': {
        target: 'http://localhost:3032',
        // target: 'https://mall.wjintian.com',
        changeOrigin: true
        // rewrite: (path) => path.replace(/^\/upload/, '')
      }
    }
  }
});
